//
//  ViewController.m
//  NetWorkSave
//
//  Created by 苗旭萌 on 15/11/17.
//  Copyright © 2015年 苗旭萌. All rights reserved.
//


#import "MySaveViewController.h"
#import "UIImageView+WebCache.h"
#import <Parse/Parse.h>


@interface MySaveViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation MySaveViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    
    self.dataArray = [NSMutableArray array];
    
    PFQuery *quert = [PFQuery queryWithClassName:@"message"];
    
    [quert whereKey:@"uid" equalTo:[user objectForKey:@"userID"]];
    
    [quert findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
        [self.dataArray setArray:objects];
        [self.tableView reloadData];
    }];
    
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CELL"];
    
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CELL" forIndexPath:indexPath];
    
    PFObject *object = self.dataArray[indexPath.row];
    
    cell.textLabel.text = [object objectForKey:@"title"];
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[object objectForKey:@"imgsrc"]]];
    
    return cell;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
